// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Enrich
{
	public sealed partial class Policy
	{
		[JsonInclude]
		[JsonPropertyName("enrich_fields")]
		public Elastic.Clients.Elasticsearch.Fields EnrichFields { get; set; }

		[JsonInclude]
		[JsonPropertyName("indices")]
		public Elastic.Clients.Elasticsearch.Indices Indices { get; set; }

		[JsonInclude]
		[JsonPropertyName("match_field")]
		public Elastic.Clients.Elasticsearch.Field MatchField { get; set; }

		[JsonInclude]
		[JsonPropertyName("name")]
		public Elastic.Clients.Elasticsearch.Name? Name { get; set; }

		[JsonInclude]
		[JsonPropertyName("query")]
		public string? Query { get; set; }
	}

	public sealed partial class PolicyDescriptor<TDocument> : SerializableDescriptorBase<PolicyDescriptor<TDocument>>
	{
		internal PolicyDescriptor(Action<PolicyDescriptor<TDocument>> configure) => configure.Invoke(this);
		public PolicyDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Fields EnrichFieldsValue { get; set; }

		private Elastic.Clients.Elasticsearch.Indices IndicesValue { get; set; }

		private Elastic.Clients.Elasticsearch.Field MatchFieldValue { get; set; }

		private Elastic.Clients.Elasticsearch.Name? NameValue { get; set; }

		private string? QueryValue { get; set; }

		public PolicyDescriptor<TDocument> EnrichFields(Elastic.Clients.Elasticsearch.Fields enrichFields)
		{
			EnrichFieldsValue = enrichFields;
			return Self;
		}

		public PolicyDescriptor<TDocument> EnrichFields<TValue>(Expression<Func<TDocument, TValue>> enrichFields)
		{
			EnrichFieldsValue = enrichFields;
			return Self;
		}

		public PolicyDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Indices indices)
		{
			IndicesValue = indices;
			return Self;
		}

		public PolicyDescriptor<TDocument> MatchField(Elastic.Clients.Elasticsearch.Field matchField)
		{
			MatchFieldValue = matchField;
			return Self;
		}

		public PolicyDescriptor<TDocument> MatchField<TValue>(Expression<Func<TDocument, TValue>> matchField)
		{
			MatchFieldValue = matchField;
			return Self;
		}

		public PolicyDescriptor<TDocument> Name(Elastic.Clients.Elasticsearch.Name? name)
		{
			NameValue = name;
			return Self;
		}

		public PolicyDescriptor<TDocument> Query(string? query)
		{
			QueryValue = query;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			writer.WritePropertyName("enrich_fields");
			JsonSerializer.Serialize(writer, EnrichFieldsValue, options);
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
			writer.WritePropertyName("match_field");
			JsonSerializer.Serialize(writer, MatchFieldValue, options);
			if (NameValue is not null)
			{
				writer.WritePropertyName("name");
				JsonSerializer.Serialize(writer, NameValue, options);
			}

			if (!string.IsNullOrEmpty(QueryValue))
			{
				writer.WritePropertyName("query");
				writer.WriteStringValue(QueryValue);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class PolicyDescriptor : SerializableDescriptorBase<PolicyDescriptor>
	{
		internal PolicyDescriptor(Action<PolicyDescriptor> configure) => configure.Invoke(this);
		public PolicyDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Fields EnrichFieldsValue { get; set; }

		private Elastic.Clients.Elasticsearch.Indices IndicesValue { get; set; }

		private Elastic.Clients.Elasticsearch.Field MatchFieldValue { get; set; }

		private Elastic.Clients.Elasticsearch.Name? NameValue { get; set; }

		private string? QueryValue { get; set; }

		public PolicyDescriptor EnrichFields(Elastic.Clients.Elasticsearch.Fields enrichFields)
		{
			EnrichFieldsValue = enrichFields;
			return Self;
		}

		public PolicyDescriptor EnrichFields<TDocument, TValue>(Expression<Func<TDocument, TValue>> enrichFields)
		{
			EnrichFieldsValue = enrichFields;
			return Self;
		}

		public PolicyDescriptor EnrichFields<TDocument>(Expression<Func<TDocument, object>> enrichFields)
		{
			EnrichFieldsValue = enrichFields;
			return Self;
		}

		public PolicyDescriptor Indices(Elastic.Clients.Elasticsearch.Indices indices)
		{
			IndicesValue = indices;
			return Self;
		}

		public PolicyDescriptor MatchField(Elastic.Clients.Elasticsearch.Field matchField)
		{
			MatchFieldValue = matchField;
			return Self;
		}

		public PolicyDescriptor MatchField<TDocument, TValue>(Expression<Func<TDocument, TValue>> matchField)
		{
			MatchFieldValue = matchField;
			return Self;
		}

		public PolicyDescriptor MatchField<TDocument>(Expression<Func<TDocument, object>> matchField)
		{
			MatchFieldValue = matchField;
			return Self;
		}

		public PolicyDescriptor Name(Elastic.Clients.Elasticsearch.Name? name)
		{
			NameValue = name;
			return Self;
		}

		public PolicyDescriptor Query(string? query)
		{
			QueryValue = query;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			writer.WritePropertyName("enrich_fields");
			JsonSerializer.Serialize(writer, EnrichFieldsValue, options);
			writer.WritePropertyName("indices");
			JsonSerializer.Serialize(writer, IndicesValue, options);
			writer.WritePropertyName("match_field");
			JsonSerializer.Serialize(writer, MatchFieldValue, options);
			if (NameValue is not null)
			{
				writer.WritePropertyName("name");
				JsonSerializer.Serialize(writer, NameValue, options);
			}

			if (!string.IsNullOrEmpty(QueryValue))
			{
				writer.WritePropertyName("query");
				writer.WriteStringValue(QueryValue);
			}

			writer.WriteEndObject();
		}
	}
}